package com.ccom.test.controller;

import com.ccom.core.common.constant.ServiceNameConstants;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @author: jjzhang24
 * @date: 2021年12月24日
 */
@Api(tags = "Cacheable 测试")
@Slf4j
@RestController
@RequestMapping(ServiceNameConstants.TEST_SERVICE_URL_PREFIX + "/cache")
public class CacheableTestController {

    @GetMapping("/testCacheable1")
    @Cacheable(value = "base1")
    public String testCacheable1(@RequestParam("s") String s) {
        log.info("test1:" + s);
        return s;
    }

    @GetMapping("/testCacheable2")
    @Cacheable(value = "base2")
    public String testCacheable2(@RequestParam("s") String s) {
        log.info("test2:" + s);
        return s;
    }

    @GetMapping("/testCacheEvict")
    @CacheEvict(value = "base1")
    public String testCacheEvict(@RequestParam("s") String s) {
        log.info("test1:" + s);
        return s;
    }
}
